﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.DataAccessLayers;
using QuanLyBanHang.SystemForms;
using STLGROUP.Layers.Common;
using STLGROUP.Layers.Presentations;

namespace QuanLyBanHang
{
    /// <summary>
    /// Form main.
    /// </summary>
    /// <author>Viet sang</author>
    /// 
    public partial class frmMainMenu : frmMainMenuBase
    {
        #region Constuctors

        public frmMainMenu()
        {
            InitializeComponent();
            
            //Get info current user.
            if (UICommon.CurrentUserInfo != null)
            {
                lblLogin.Text = string.Format("Chào mừng người dùng: {0} ",UICommon.CurrentUserInfo.HoTenNhanVien??string.Empty);
            }
        }

        #endregion

        #region Events

        private void btnKhachHang_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF001());
        }

        private void btnPhanQuyenNhom_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new frmPhanQuyenNhom());
        }

        private void btnNhomND_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new frmNhomNguoiDung());
        }

        private void btnModule_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new frmModule());
        }

        private void btnThongTinNguoiDung_Click(object sender, EventArgs e)
        {
            if (UICommon.CurrentUserInfo != null && UICommon.CurrentUserInfo.TenDangNhap != "root")
            {
                ShowFromDialog(new frmInfoOfUser() { User = UICommon.CurrentUserInfo });
            }
            else
            {
                UICommon.ShowMessgeString("Tài khoản root không sử dụng được chức năng này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btnResetPassword_Click(object sender, EventArgs e)
        {
            if (UICommon.CurrentUserInfo.IDNhomNguoiDung == (int?)StructsEnums.EnumNhomNguoiDung.QuanLy)
            {
                ShowFromDialog(new frmResetPassword());
            }
            else
            {
                UICommon.ShowMessgeString("Chức năng này dành riêng cho quản trị", "Thông báo");
            }
        }

        private void btnSaoLuuPhucHoi_Click(object sender, EventArgs e)
        {

            if (UICommon.CurrentUserInfo.IDNhomNguoiDung == (int?)StructsEnums.EnumNhomNguoiDung.QuanLy)
            {
                ShowFromDialog(new frmBackup());
            }
            else
            {
                UICommon.ShowMessgeString("Chức năng này dành riêng cho quản trị", "Thông báo");
            }            
        }

        private void btnCaiDat_Click(object sender, EventArgs e)
        {
            ShowFromDialog(new frmThemes());
        }

        private void btnLogOut_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }

        private void btnNhanVien_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF003());
        }

        private void btnNhaCungCap_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF002());
        }

        private void btnLoaiSanPham_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF003());
        }

        private void btnSanPham_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF004());
        }

        private void btnBanSi_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF006A());
        }

        private void btnDatHangNCC_Click(object sender, EventArgs e)
        {
            ShowChildFormHasPermission(new MF008());
        }

        private void btnReportBangBaoGia_Click(object sender, EventArgs e)
        {
            ShowChildForm(new RF002());
        }

        private void btnReportSanPhamNhapThem_Click(object sender, EventArgs e)
        {
            ShowChildForm(new RF003());
        }
        
        private void btnTinhThanh_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF002());
        }

        private void btnLoaiNhanVien_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF007());
        }

        private void btnDanToc_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF004());
        }

        private void btnTonGiao_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF005());
        }

        private void btnPhongBan_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF006());
        }

        private void btnChucVu_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF001());
        }

        private void btnThongTinChuongTrinh_Click(object sender, EventArgs e)
        {
            ShowChildForm(new frmAboutApp());
        }

        private void btnThongTinTacGia_Click(object sender, EventArgs e)
        {
            ShowChildForm(new frmAboutUs());
        }

        private void btnReportSanPhan_Click(object sender, EventArgs e)
        {
            ShowChildForm(new RF001());
        }

        private void btnCongNoNCC_Click(object sender, EventArgs e)
        {
            ShowChildForm(new RF005());
        }

        private void btnHoaDonSuDung_Click(object sender, EventArgs e)
        {
            ShowChildForm(new MF009());
        }

        private void btnReportDoanhThu_Click(object sender, EventArgs e)
        {
            ShowChildForm(new RF006());
        }

        private void btnHoTroTuXa_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Application.StartupPath + @"\Add-on\TeamViewerQS_vi.exe";
                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy trình hỗ trợ từ xa. Vui lòng kiểm tra lại.");
            }
        }

        private void btnMayTinh_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("calc");
            }
            catch
            {
                MessageBox.Show("Không thể khởi động máy tính. Vui lòng thử lại.");
            }
        }

        private void btnKhuyenMai_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF008());
        }

        private void btnNhapHang_Click(object sender, EventArgs e)
        {
            ShowChildForm(new MF010());
        }

        private void btnReportHoaDon_Click(object sender, EventArgs e)
        {

        }

        private void btnBanLe_Click(object sender, EventArgs e)
        {

        }

        private void btnTroGiupSub_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Application.StartupPath + @"\HuongDanSuDung\HuongDanSuDungQLBH.pdf";
                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                MessageBox.Show("Không thể mở trợ giúp. Vui lòng kiểm tra lại.");
            }
        }

        private void btnTroGiup_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Application.StartupPath + @"\HuongDanSuDung\HuongDanSuDungQLBH.pdf";
                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                MessageBox.Show("Không thể mở trợ giúp. Vui lòng kiểm tra lại.");
            }
        }

        //Giam gia hoa don
        private void buttonItem1_Click(object sender, EventArgs e)
        {
            ShowDialogHasPermission(new CF009());
        }

        private void btnDonHangSuDung_Click(object sender, EventArgs e)
        {
            ShowChildForm(new MF007());
        }


        #endregion       
                
        #region Private methods

        private void ShowFormOnlyKeToan(frmReportBase frm)
        {
            if (UICommon.CurrentUserInfo.IDNhomNguoiDung != (int)StructsEnums.EnumNhomNguoiDung.BanHang)
            {
                frm.ShowDialog();
            }
            else
            {
                UICommon.ShowMessgeString("Nhân viên bán hàng không được sử dụng chức năng này", "Thông báo");
                return;
            }
        }

        #endregion       
    }
}
